package com.cspm.ahjy.bc.office.enums;

import java.text.DecimalFormat;


/**
 * 纸张大小枚举
 * @author ServerZhang
 * @date 2017年10月17日
 */
public enum PaperSizeEnum {
	
	XINZHI("信纸",21.59,27.94),
	XINZHI_2("信纸",27.94,21.59),
	LAW("法律专用纸",21.59,35.56),
	LAW_2("法律专用纸",35.56,21.59),
	EXECUTIVE("Executive",18.41,26.67),
	EXECUTIVE_2("Executive",26.67,18.41),
	A4("A4",21.0,29.7),
	A4_2("A4",29.7,21.0),
	A5("A5",14.8,21.0),
	A5_2("A5",21.0,14.8),
	B5("B5",18.2,25.7),
	B5_2("B5",25.7,18.2),
	MSG_10("信封 #10",24.13,24.13),
	MSG_10_2("信封 #10",24.13,24.13),
	MSG_DL("信封 DL",11.0,22.0),
	MSG_DL_2("信封 DL",22.0,11.0),
	MSG_C5("信封 C5",16.2,22.9),
	MSG_C5_2("信封 C5",22.9,16.2),
	MSG_B5("信封 B5",17.6,25.0),
	MSG_B5_2("信封 B5",25.0,17.6),
	MSG_MONARCH("信封 Monarch",9.84,19.05),
	MSG_MONARCH_2("信封 Monarch",19.05,9.84),
	JAN("日式明信片",10.0,14.8),
	JAN_2("日式明信片",14.8,14.8),
	EXECUTIVE_JIS("Executive(JIS)",21.59,32.99),
	EXECUTIVE_JIS_2("Executive(JIS)",32.99,21.59),
	K16("16K 197×273 mm",19.68,27.3),
	K16_2("16K 197×273 mm",27.3,19.68),
	KAI16("16开",18.4,26.0),
	KAI16_2("16开",26.0,18.4),
	K32("32开",13.0,18.4),
	K32_2("32开",18.4,13.0),
	K32_BIG("大32开",14.0,20.3),
	K32_BIG_2("大32开",20.3,14.0);
	
	private static final DecimalFormat df = new DecimalFormat("######0.00");
	private static final DecimalFormat df2 = new DecimalFormat("######0");//四舍五入成整数
	
	String paperName;//纸张大小名称
	Double width;//纸张宽度
	Double height;//纸张高度
	
	private PaperSizeEnum(String paperName, Double width, Double height){
		this.paperName = paperName;
		this.width = width;
		this.height = height;
	}
	
	public String getPaperName() {
		return paperName;
	}
	public void setPaperName(String paperName) {
		this.paperName = paperName;
	}
	public Integer getWidth() {
		String format = df2.format(width * 567);
		return Integer.parseInt(format);
	}
	public void setWidth(Integer width) {
		this.width = Double.parseDouble(df.format(width / 567.0));
	}
	public Integer getHeight() {
		String format = df2.format(height * 567);
		return Integer.parseInt(format);
	}
	public void setHeight(Integer height) {
		this.height = Double.parseDouble(df.format(height / 567.0));
	}
	
	public static PaperSizeEnum getByName(String paperName){
		for(PaperSizeEnum e : PaperSizeEnum.values()){
			if (e.getPaperName().equals(paperName)) {
				return e;
			}
		}
		return null;
	}
	
	public static PaperSizeEnum getBySize(Integer width, Integer height){
		if (null == width || height == null) {
			return null;
		}
		for(PaperSizeEnum e : PaperSizeEnum.values()){
			if (width.equals(e.getWidth()) && height.equals(e.getHeight())) {
				return e;
			}
		}
		return null;
	}
	
	
	
}
